package com.tms.app.tms.ui;

import com.tms.app.tms.app.Constant;
import com.tms.app.tms.bean.WaybillInfo;
import com.tms.app.tms.bean.response.BaseResponse;
import com.tms.app.tms.bean.response.WayInfoRes;
import com.tms.app.tms.bean.response.WaybillListRes;
import com.tms.app.tms.ui.base.presenter.AbsServicexUtils;
import com.tms.app.tms.ui.base.presenter.ComPresenter;

import org.xutils.http.RequestParams;

/**
 * Created by Administrator on 2017/12/3 0003.
 */

public class WBillPresenter extends ComPresenter {

    private int dispatchId;

    @Override
    public void onSuccess(String result) {
        super.onSuccess(result);
        if (requestType==1){//运单详情
            WayInfoRes wayInfoRes=gson.fromJson(result, WayInfoRes.class);
            if (wayInfoRes.getCode()==200){
                sendMsgToView(wayInfoRes.getData());
                return;
            }
        }
        if(requestType==2){//
            BaseResponse baseResponse=gson.fromJson(result,BaseResponse.class);
            baseResponse.setRequestType(requestType);
            sendMsgToView(baseResponse);
        }
    }

    /******
     * 运单详情
     * @param token
     * @param dispatchId
     */
    public void waybillDetail(String token, int dispatchId){
        this.token=token;
        this.dispatchId=dispatchId;
        requestType=1;
        RequestParams params=new RequestParams(Constant.WAY_BILL_INFO);
        params.addBodyParameter("token",token);
        params.addBodyParameter("dispatchId",dispatchId+"");
        params.addBodyParameter("showLoading", AbsServicexUtils.showAndHideLoading);
        getObjectFromServer(params,1);
    }

    /***
     * 预录保存
     * @param params
     */
    public void saveRecode(RequestParams params){
        requestType=2;
        getObjectFromServer(params,1);
    }

    @Override
    public void onRefresh() {
        super.onRefresh();
        waybillDetail(token,dispatchId);
    }
}
